package com.jadcon.bedbreakfast.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.jadcon.bedbreakfast.domain.Guest;
import com.jadcon.bedbreakfast.domain.guestService;


@Controller
public class GuestController{
	
	@Autowired
	private guestService guestService;
	
	@RequestMapping("/guest.html")
	public ModelAndView guest() {
		System.out.println("GuestController.guest() begin...");
		// get data from model
		List<Guest> guestList = guestService.getGuestList();
		
		// add data to ModelAndView
		ModelAndView mav = new ModelAndView("guest");
		mav.addObject("guestList", guestList);
		return mav;
		// map ("key", value)

}
	
	@RequestMapping("/guestsearch.html")
	public ModelAndView guestSearch(@RequestParam String fullname) {
		System.out.println("GuestController.guestSearch() begin...");
		
		// get data from model
		Guest guest = guestService.findGuestByFullname(fullname);
		
		
		// add data to ModelAndView
		ModelAndView mav = new ModelAndView("guestDetail"); // "guestdetail" is the view name
		mav.addObject("guest", guest);
		return mav;
	}
		// map ("key", value)
	
}